package mt3051;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class Main {
	public static int MAXN = 200001;
	public static int LIMIT = 20;
	public static int[][] stgcd = new int[MAXN][LIMIT];
	public static int[] arr = new int[MAXN];
	public static int[] log2 = new int[MAXN];

	//输入优化模板开始
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
	static int rd() throws IOException {
		st.nextToken();
		return (int) st.nval;
	}
	//输入优化模板结束
	
	public static void build(int n) {
		log2[0] = -1;
		for (int i = 1; i <= n; i++) {
			stgcd[i][0] = arr[i];
			log2[i] = log2[i / 2] + 1;
		}
		for (int p = 1; p <= log2[n]; p++) {
			for (int i = 1; i + (1 << p) - 1 <= n; i++) {
				stgcd[i][p] = gcd(stgcd[i][p - 1], stgcd[i + (1 << (p - 1))][p - 1]);
			}
		}
	}

	public static int query(int l, int r) {
		int p = log2[r - l];
		if (l == r)
			return arr[l];
		return gcd(stgcd[l][p], stgcd[r - (1 << p) + 1][p]);
	}

	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static void main(String[] args) throws IOException {
		int n = rd();
		int m = rd();
		
		for (int i = 1; i <= n; i++) {
			arr[i] = rd();
		}
		build(n);
		StringBuilder B = new StringBuilder();
		for (int i = 0; i < m; i++) {
			
			int l = rd();
			int r = rd();
			B.append(query(l, r));
			B.append("\n");
		}
		System.out.println(B.toString());
	}

}
